package com.mvm.store.service.base;

import java.io.Serializable;
import java.util.List;

import javax.persistence.PersistenceContext;

import org.springframework.transaction.annotation.Transactional;

import com.mvm.store.domain.dao.base.AbstractDAO;

@Transactional
public class AbstractServiceImpl<Domain extends Serializable, Key extends Serializable> implements AbstractService<Domain, Key> {

	private AbstractDAO<Domain, Key> dao;

	@PersistenceContext
	public void setDao(AbstractDAO<Domain, Key> dao) {

		this.dao = dao;
	}
	
	public AbstractDAO<Domain, Key> getDao() {
	
		return dao;
	}

	public List<Domain> findAll() {

		return dao.list();
	}

	public void save(Domain client) {

		dao.save(client);
	}

	public void update(Domain client) {

		dao.update(client);
	}
	
	public void remove(Key id) {

		Domain client = find(id);
		if (client != null) {
			dao.delete(client);
		}
	}

	public Domain find(Key id) {

		return dao.load(id);
	}

}
